package pl.com.qapps.datastore.berkeley.impl;

import java.io.IOException;
import java.util.List;

import pl.com.qapps.datastore.SinglePropertyStore;

import com.google.appengine.api.datastore.Entity;
import com.sleepycat.je.Database;
import com.sleepycat.je.Environment;
import com.sleepycat.je.ForeignKeyDeleteAction;
import com.sleepycat.je.SecondaryConfig;

public class BerkeleyIndexStore extends StoreTable implements
		SinglePropertyStore {

	private Database db;

	public BerkeleyIndexStore(Environment env, String filename,
			Database entities, boolean reverseValue) {
		super(env);

		SecondaryConfig cfg = new SecondaryConfig();
		cfg.setAllowCreate(true);
		cfg.setTransactional(true);
		cfg.setSortedDuplicates(true);
		cfg.setKeyPrefixing(true);
		cfg.setForeignKeyDeleteAction(ForeignKeyDeleteAction.CASCADE);
		cfg.setMultiKeyCreator(new SinglePropertyKeyCreator(
				EntityBindings.ENTITY_BINDING, reverseValue));
		// ascCfg.setBtreeComparator(COMPARATOR);

		db = env.openSecondaryDatabase(null, filename, entities, cfg);
	}

	@Override
	public List<Entity> get(String kind, String property, Object value) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void close() throws IOException {
		db.close();
	}

	@Override
	public void delete(String kind, String property, Object value) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("not supported yet");
	}

}
